function alertDiv(title,url,width,height){
	if(width==null)width=800;
	if(height==null)height=600;
	messager.iframe(url,title,width,height);
	/**var i=messager.confirm('确定删除这些记录吗？',function(){
		alert('yes');
		messager.close(i);
	},function(){
		alert('no');messager.close(i);
	});
	**/
	//iframe框架
	//messager.iframe('http://www.aboutit.cn','程序员看世界',1200,700);
}

/****************************************
 @Name：基于对象dialog
 @Author：life
 @Date：2014-08-13
 @Blog：http://blogs.aboutit.cn
 @Copyright：life
 @官网：
        
 */
;(function(window, $, undefined) {
	
	/***
	 * 参考Layer代码:https://github.com/sentsin/messager
	 */
	var path = '', //组件存放目录，为空表示自动获取(不用填写host，相对站点的根目录即可)。
	$, win, ready = {
		    getPath: function(){
		        var js = document.scripts, jsPath = js[js.length - 1].src;
		        return path ? path : jsPath.substring(0, jsPath.lastIndexOf("/") + 1);
		    },
		    
		    //五种原始层模式
		    type: ['info', 'page', 'iframe', 'loading', 'tips','ajax']
	};
	//创建window的内置对象，这样调用
	//默认内置方法。
	window.messager = {
	    v: '0.0.1',
	    ie6: !!window.ActiveXObject&&!window.XMLHttpRequest,
	    index: 0,
	    path: ready.getPath(),
	    close : function(index){messager.close(index);},
	    //载入模块
	    use: function(module, callback){
	        var i = 0, head = $('head')[0];
	        var module = module.replace(/\s/g, '');
	        var iscss = /\.css$/.test(module);
	        var node = document.createElement(iscss ? 'link' : 'script');
	        var id = module.replace(/\.|\//g, '');
	        if(iscss){
	            node.type = 'text/css';
	            node.rel = 'stylesheet';
	        }
	        node[iscss ? 'href' : 'src'] = /^http:\/\//.test(module) ? module : messager.path + module;
	        node.id = id;
	        if(!$('#'+ id)[0]){
	            head.appendChild(node);
	        }
	        if(callback){
	            if(document.all){
	                $(node).ready(callback);
	            } else {
	                $(node).load(callback);
	            }
	        }
	    },
	    
	    /**
	     * 弹出文本信息，
	     * @param msg  信息
	     * @param icon 内容前面的ICON，默认√ 
	     * @param fn 回调函数，选择确定之后执行的函数
	     * @param yes 
	     * @returns
	     */
	    info: function(msg,fn,icon){
	    	var isfn = (typeof fn === 'function'), conf = {
	            dialog: {msg: msg, icon:icon},
	            btn_array:[{'name':'&#x786E;&#x5B9A;','state':'hl','callback':isfn?fn:messager.close}]
	        };
	        isfn || (conf.title = fn);
	        return $.messager(conf);
	    }, 
	    
	    confirm: function(msg, yes, no){ 
	    	 var isYes = (typeof yes === 'function'),isNo = (typeof no === 'function'), conf = {
	             dialog: {msg: msg},
	             type:1,
	             btn_array:[{'name':'确定','state':'hl','callback':isYes?yes:messager.close},{'name':'取消','state':'normal','callback':isNo?no:messager.close}]
	         };
	    	 isYes || (conf.title = isYes);
	         return $.messager(conf); 
	    },
	    //简单请求iframe
	    iframe :function(url,title,width,height,scrolling){
	    	var isScroll=(typeof scrolling!='undefined'),isWH=(typeof(width)!='undefined'), conf = {
	    			title:title,
	    			type:3,fitToView:isWH?false:true,width:width,height:height,
	    			iframe:{'src':url,'scrolling':isScroll?scrolling:'auto'},
		    };
	    	return $.messager(conf); 
	    },
	    //加载层快捷引用
	    load: function(parme, icon){
	    	
	    }, 
	    
	    //tips层快捷引用
	    tips: function(html, follow, parme, maxWidth, guide, style){
	    }
	};
	
	//缓存常用字符
	var doms = ['messager-title', 'xubox_iframe', '.xubox_title', '.xubox_text', '.xubox_page', '.xubox_main'];
	
	//弹出层实例对象类  --构造函数
	var Messager = function(setings){    
		var that = this, config = that.config;//this.config 是原型的属性
	    messager.index++;
	    that.index = messager.index;
	    that.config = $.extend({} , config , setings);//合并配置
	    that.config.dialog = $.extend({}, config.dialog , setings.dialog);
	    that.config.page = $.extend({}, config.page , setings.page);
	    that.config.iframe = $.extend({}, config.iframe , setings.iframe);    
	    that.config.loading = $.extend({}, config.loading , setings.loading);
	    that.config.tips = $.extend({}, config.tips , setings.tips);
	    that.config.btn_array = $.extend({}, config.btn_array , setings.btn_array);
	    that.current=null;
	    that.container=null;
	    that.creat();//调用create方法
	};
	Messager.pt = Messager.prototype;
	//默认配置
	Messager.pt.config = {
		
		model:true,
		width     : 800,
		height    : 600,
	    type: 0,
	    title: '信息',
	    fitToView   : true,
	    
	    minHeight : 100,
		maxWidth  : 9999,
		maxHeight : 9999,
	    minWidth  : 100,
	    autoSize   : true,
		autoHeight : false,
		autoWidth  : false,
		autoResize  : true,
		btn_array:[{'name':'&#x786E;&#x5B9A;','state':'hl','callback':function(index){messager.close(index);}},{'name':'&#x53D6;&#x6D88;','state':'normal','callback':function(index){messager.close(index);}}],
		dialog: {btns: 1, btn: ['&#x786E;&#x5B9A;','&#x53D6;&#x6D88;'], type : 8, msg: '', yes: function(index){layer.close(index);}, no: function(index){layer.close(index);}},
		move: '.xubox_title',
		
	    time: 0,
	    zIndex: 19891014, 
	    iframe: {src: 'http://www.aboutit.cn', scrolling: 'auto'},
	    success: function(layer){}, //创建成功后的回调
	    close: function(index){ layer.close(index);}, //右上角关闭回调
	    end: function(){}, //终极销毁回调
	    // HTML templates
		tpl: {
			overlayer     : '<div id="messager-overlayer{index}" class="messager-overlayer"></div>',
			wrap     : '<div id="messager-wrap{index}" class="messager-wrap" tabIndex="-1"></div>',
			header     : '<div class="messager-header"></div>',
			title     : '<div class="messager-title"></div>',
			closeBtn : '<a title="Close" class="messager-close" href="javascript:;">×</a>',
			content : '<p class="messager-content"></p>',
			inner : '<div class="messager-inner"></div>',
			icon : '<span class="messager-icon"></span>',
			btnWrap : '<div class="messager-buttons"></div>',
			button : '<a href="javascript:;" class="messager-button">确定</a>',
			footer : '<div class="messager-footer"></div>',
			
			iframe   : '<iframe id="messager-frame{index}" name="messager-frame{index}" class="messager-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen' + (this.ie6 ? ' allowtransparency="true"' : '') + '></iframe>',
			error    : '<p class="messager-error">The requested content cannot be loaded.<br/>Please try again later.</p>'
		}
	};
	
	//渲染messager的dom对象，返回对象
	Messager.pt.render = function(html){
	   var that=this,body = $("body"),render={};
	   //需要创建overLayer吗？
	   if(that.config.model){
		   that.overlayer();
	   }
	   var $wrap=$(that.setId(that.config.tpl.wrap));
	   body.append($wrap);
	   //创建标题bar
	   var $header=$(that.config.tpl.header);
	   $header.appendTo($wrap);
	   //创建标题及是否关闭
	   $title=$(that.config.tpl.title);
	   $title.appendTo($header);
	   //创建关闭btn
	   $close=$(that.config.tpl.closeBtn);
	   $close.click(function(){
		   messager.close(that.index);
	   });
	   $close.appendTo($header);
	   $title.html(that.config.title);
	   //创建内容
	   $inner=$(that.config.tpl.inner);
	   $content=$(that.config.tpl.content);
	   $inner.appendTo($wrap);
	   $icon=$(that.config.tpl.icon);
	   $icon.appendTo($inner);
	   $content.appendTo($inner);
	   $footer=$(that.config.tpl.footer);
	   $btnWrap=$(that.config.tpl.btnWrap);
	   $footer.appendTo($wrap);
	   $btnWrap.appendTo($footer);
	   //返回渲染之后的组件对象
	   render.wrap=$wrap;
	   render.header=$header;
	   render.title=$title;
	   render.close=$close;
	   render.content=$content;
	   render.inner=$inner;
	   render.icon=$icon;
	   render.btnWrap=$(that.config.tpl.btnWrap);
	   render.footer=$footer;
	   render.btnWrap=$btnWrap;
	   
	   //设置当前Messager 
	   that.current= $('#messager-wrap'+ that.index);
	   that.current.attr('index',that.index);
	   that.container=render;
	   
	   return render;
	};
	
	//创建遮罩
	Messager.pt.overlayer = function(){
		   var that=this,body = $("body");
		   body.append($(that.setId(that.config.tpl.overlayer)));
	};
	
	Messager.pt.setId=function(html){ 
		var that=this;
		return html.replace(/{index}/g,that.index);
	};
	
	
	//创建不同的弹出层
	Messager.pt.creat = function(){
	    var that = this , space = '', config = that.config, dialog = config.dialog, times = that.index;
	    var page = config.page;
	    render=that.render();
	    switch(config.type){
	        case 0: //简单的提示信息
	        	render.icon.addClass("messager-icon-type-info").css('display','none');
	        	render.content.html(dialog.msg);
	        break;
	        
	        case 1:
	        	render.icon.addClass("messager-icon-type-question").css('display','none');
	        	render.content.html(dialog.msg);
	        break;
	        
	        case 3:
	        	 var $iframe = $(that.setId(config.tpl.iframe)),heg = that.current.height();
	        	 render.inner.html($iframe);
	        	 render.inner.css({'padding':0,'margin':0});
	        	 $iframe.css({'height': heg - render.title.height(),'width':that.current.width()});
	        	 $iframe.attr('scrolling', config.iframe.scrolling);
	        	 $iframe.attr('src', config.iframe.src);
	             
	        break;
	    };
	    //设置属性（自适应高宽，是否可以拖动等）
	    that.set();
	};
	
	/**
	 * 根据配置设置属性
	 */
	Messager.pt.set=function(){
		    var that = this;
		    var config = that.config;
		    var dialog = config.dialog;
		    var page = config.page;
		    var loading = config.loading;
		    var current = that.current;//当前操作的messager对象(jq对象)
		    
		    that.events();//设置事件
		    that.fitToView();//设置fitToView
		    //that.reSizeLayer();//设置是否自动resize
		    
		    that.move();//设置是否可以拖动
		   
	};
	
	Messager.pt.reSizeLayer=function(){
		var that=this,config=that.config,
		current = that.current,
		_true_width=current.outerWidth(),
		 _true_height=current.outerHeight();
		//坐标自适应浏览器窗口尺寸
	    if(config.autoResize){
	        win.on('resize', function(){
	        	 current.css({'width':_true_width,"height":_true_height,marginLeft: 0 - _true_width / 2, 
	   		     marginTop: 0 - _true_height / 2 });
	        });
	    }
	}
	
	Messager.pt.fitToView=function(){
		 var that = this;
		 var current = that.current;//当前操作的messager对象(jq对象)
		 var config = that.config,
		 _true_width=current.outerWidth(),
		 _true_height=current.outerHeight(),
		// maxHeight=config.maxHeight,
		// maxWidth=config.maxWidth,
		 set_width=config.width,
		 set_hegith=config.height;
		// Try to fit inside viewport (including the title)
		if (config.fitToView) {
			 //重新计算wrap的宽度及位置,如果是简单的对话框，直接加载内容后，计算高度宽度，然后定位；如果是自适应，则需要等待内容填充完成后计算，后期加入maxWidth,maxHeight等
			current.css({'width':_true_width,"height":_true_height,marginLeft: 0 - _true_width / 2, 
		     marginTop: 0 - _true_height / 2 });
		}else{
			current.css({'width':set_width,"height":set_hegith,marginLeft: 0 - set_width / 2, 
			     marginTop: 0 - set_hegith / 2 });
			//iframe 自适应
			if(config.type==3){
				 var $iframe = $(that.current.find('#messager-frame'+that.index)),heg = that.current.height();
	        	 $iframe.css({'height': heg - render.title.height(),'width':that.current.width()});
			}
		}
	};
	
	//设置拖动
	Messager.pt.move=function(){
		var that = this,
		current = that.current,//当前操作的messager对象(jq对象)
		config = that.config,
		container = that.container,
		title=container.title;
		//是否可以拖动
		if(!that.config.move)return;
		title.css({'cursor': 'move'});
		title.attr('move','ok');
		var conf = {
		        setY: 0,
		        moveLayer: function(){
		        	var lefts=0,tops=0
		            if(parseInt(current.css('margin-left')) == 0){
		                var lefts = parseInt(conf.move.css('left'));
		            }else{
		                var lefts = parseInt(conf.move.css('left')) + (-parseInt(current.css('margin-left')));
		            }
		            if(parseInt(current.css('margin-top')) == 0){
		                var tops = parseInt(conf.move.css('top'));
		            }else{
		                var tops = parseInt(conf.move.css('top')) + (-parseInt(current.css('margin-top')));
		            }
		            if(current.css('position') !== 'fixed'){
		                lefts = lefts - current.parent().offset().left;
		                conf.setY = 0
		            }
		            current.css({left: lefts, top: parseInt(tops)});
		        }
		};
		$(title).on('mousedown', function(M){    
		        M.preventDefault();
		        if($(this).attr('move') === 'ok'){
		            conf.ismove = true;
		            var xx = current.offset().left, yy = current.offset().top, ww = current.outerWidth(), hh = current.outerHeight();
		            if(!$('#messager-mover-layer')[0]){
		                $('body').append('<div id="messager-mover-layer" class="messager-mover-layer" style="left:'+ xx +'px; top:'+ yy +'px; width:'+ ww +'px; height:'+ hh +'px; z-index:2147483584"></div>');
		            }
		            conf.move = $('#messager-mover-layer');
		            config.moveType && title.css({opacity: 0});
		           
		            conf.moveX = M.pageX - conf.move.position().left;
		            conf.moveY = M.pageY - conf.move.position().top;
		            current.css('position') !== 'fixed' || (conf.setY = win.scrollTop());
		        }
		    });
		    
		    $(document).mousemove(function(M){
		        if(conf.ismove){
		        	 var offsetX = M.pageX - conf.moveX, offsetY = M.pageY - conf.moveY;
		             M.preventDefault();

		             //控制元素不被拖出窗口外
		             if(!config.moveOut){
		                 conf.setY = win.scrollTop();
		                 var setRig = win.width() - conf.move.outerWidth(), setTop =conf.setY;               
		                 offsetX < 0&&(offsetX=0);
		                 offsetX > setRig && (offsetX = setRig); 
		                 offsetY < setTop && (offsetY = setTop);
		                 offsetY > win.height() - conf.move.outerHeight() + conf.setY && (offsetY = win.height() - conf.move.outerHeight() + conf.setY);
		             }
		             conf.move.css({left: offsetX, top: offsetY});    
		             config.moveType && conf.moveLayer();
		             
		             offsetX = null;
		             offsetY = null;
		             setRig = null;
		             setTop = null
		        }                                                 
		    }).mouseup(function(){
		        try{
		            if(conf.ismove){
		                conf.moveLayer();
		                conf.move.remove();
		            }
		            conf.ismove = false;
		        }catch(e){
		            conf.ismove = false;
		        }
		        config.moveEnd && config.moveEnd();
		    });
	};
	
	Messager.pt.addBtn=function(btn,seq){
		var that = this,config=that.config,
		container = that.container;
		$button=$(config.tpl.button);
		$button.attr('id','messager-btns-'+seq);
		$button.addClass(btn.state);
		$button.click(function(){
    		btn.callback(that.index);
    	});
		$button.html(btn.name);
    	container.btnWrap.append($button);
	};
	
	//设置按钮的事件
	Messager.pt.events=function(){
		var that = this,
		config = that.config,
		container = that.container,
		btn_array = that.config.btn_array;
		
		switch(config.type){
	            case 0:
	            	//加入确定按钮
	            	container.btnWrap.show();
	            	that.addBtn(btn_array[0],0);
	            break;
	            case 1:
	            	//加入确定按钮
	            	container.btnWrap.show();
	            	that.addBtn(btn_array[0],0);
	            	that.addBtn(btn_array[1],1);
	            break;
	            case 2:
	            	
	            break;                
	    }
	};
	
	//关闭总方法
	messager.close = function(index){
	    var layero = $('#messager-wrap' + index);
	    if(!layero[0]){
	        return;
	    }
	    layero[0].innerHTML = '';
	    layero.remove();
	    $('#messager-overlayer'+index).remove();
	};
	
	//关闭所有层
	messager.closeAll = function(type){
	    $.each($('.messager-wrap'), function(){
	        var othis = $(this);
	        messager.close(othis.attr('index'));
	    });
	};
	
	//主入口
	ready.run = function(){
	    $ = jQuery; 
	    win = $(window);
	    doms.html = $('html');
	    messager.use('skin/messager.css');
	    $.messager = function(config){
	        var o = new Messager(config);
	        return o.index;
	    };
	    //(new Image()).src = messager.path + 'skin/default/xubox_ico0.png';
	};
	if("function" === typeof define){
	    define(function(){
	        ready.run();
	        return messager;
	    });
	}else{
	    ready.run();
	}
	
}(window, jQuery));